package com.zline.foodraise.view;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zline.foodraise.R;
import com.zline.foodraise.adapter.HotCommentListAdapter;
import com.zline.foodraise.constant.Constant;
import com.zline.foodraise.entity.CommentBean;
import com.zline.foodraise.entity.JsResourceBean;
import com.zline.foodraise.listener.RecyclerItemClicked;
import com.zline.foodraise.util.LUtil;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/11/19.
 * 评论列表中的热门评论
 */
@EViewGroup(R.layout.comment_list_header_view)
public class HotCommentListView extends RelativeLayout {
    private static final String LOG_TAG = HotCommentListView.class.getSimpleName();
    @ViewById(R.id.hot_comment_list_recyclerView)
    RecyclerView hot_recyclerView;
    SparseArray<CommentBean> hotCommentArray;
    @Bean
    HotCommentListAdapter hotCommentAdapter;
    MyLinearLayoutManager hotLayoutManager;
    Context cxt;
    RecyclerItemClicked itemClicked;
    @ViewById(R.id.hot_comment_tv)
    TextView recycler_title_tv;

    public HotCommentListView(Context context) {
        super(context);
        this.cxt = context;
    }


    public void bindHeaderData(SparseArray<CommentBean> array, int resourceType,RecyclerItemClicked itemClicked) {
        this.itemClicked = itemClicked;
        hotCommentArray=array;
        if(resourceType==2){//如果是筹列表变成热门话题
            recycler_title_tv.setText(R.string.hot_topic);
        }
        setHotCommentRecyclerView();

    }

    //初始化热门评论RecyclerView
    void setHotCommentRecyclerView() {
        hot_recyclerView.setItemAnimator(new DefaultItemAnimator());
        hot_recyclerView.setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);//去除阴影
        hotLayoutManager = new MyLinearLayoutManager(cxt);
        hotLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        hot_recyclerView.setLayoutManager(hotLayoutManager);
        hot_recyclerView.setHasFixedSize(true);
        hotCommentAdapter.setAdapterData(hotCommentArray);
        hotCommentAdapter.setRecycleItemClickListener(itemClicked);
        hotCommentAdapter.setRecycleFlag(Constant.HOT_COMMENT_FLAG);
        hot_recyclerView.setAdapter(hotCommentAdapter);
    }

}
